import dayjs from 'dayjs';
import { WEEKS_ZH } from '@/common/const'

/**
 * 格式化时间戳
 * @param {string} timestamp 时间戳
 * @returns {string} 格式化后的时间 
 * */
const formatTimestamp = (timestamp) => {
  const date = dayjs(timestamp);
  const now = dayjs();
  const diffDay = now.diff(date, 'day');
  const diffWeek = now.diff(date, 'week');
  const diffYear = now.diff(date, 'year');
  // 今天
  if (diffDay === 0) {
    return date.format('HH:mm');
  }
  // 本周内
  if (diffWeek === 0) {
    return '星期' + WEEKS_ZH[date.day()];
  }
  // 今年内
  if (diffYear === 0) {
    return date.format('MM-DD');
  }
  // 去年以前
  return date.format('YYYY-MM-DD');
}


const goContentDetail = (params) => {
  console.log(params)
  uni.$u.route({
    url: '/pagesB/content/contentDetail',
    params
  })
}


export {
  formatTimestamp,
  goContentDetail
}